package com.dailywork.basepro.lambda;

import java.util.*;

/**
 * @author Benjamin Winterberg
 */
public class Lambda1 {

    public static void main(String[] args) {
        List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");

        names.sort(Comparator.naturalOrder());
        System.out.println(String.join(",", names));

        names.sort(String::compareTo);
        System.out.println(String.join(",", names));

        names.sort(Collections.reverseOrder());
        System.out.println(String.join(",", names));

        List<String> names2 = Arrays.asList("peter", null, "anna", "mike", "xenia");
        names2.sort(Comparator.nullsFirst(String::compareTo));
        names2.sort(Comparator.nullsLast(String::compareTo));
        System.out.println(names2);

        List<String> names3 = null;
        Optional.ofNullable(names).ifPresent(list -> list.sort(Comparator.naturalOrder()));
        System.out.println(names3);
    }
}
